/*
 *  Copyright (C) 2011 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * pn_Config.java
 *
 * Created on 03/06/2011, 18:14:32
 */
package kuasar.plugin.servermanager.gui;

import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import kuasar.plugin.Intercom.GUI;
import kuasar.plugin.servermanager.Config;
import kuasar.plugin.utils.pn_Info;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */
public class pn_Config extends kuasar.plugin.classMod.AbstractPanel {

    pn_Main main;
    /** Creates new form pn_Config */
    public pn_Config(pn_Main main) {
        this.main=main;
        initComponents();
        lbl_Clear.setVisible(false);
        lbl_warning.setVisible(false);
        loadConfig();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pn_Container = new javax.swing.JPanel();
        lbl_Password = new javax.swing.JLabel();
        lbl_titGlobal = new javax.swing.JLabel();
        pwd_password = new javax.swing.JPasswordField();
        lbl_login = new javax.swing.JLabel();
        lbl_username = new javax.swing.JLabel();
        txt_user = new javax.swing.JTextField();
        cb_DNIe = new javax.swing.JCheckBox();
        lbl_Keystore = new javax.swing.JLabel();
        lbl_ksFile = new javax.swing.JLabel();
        lbl_Clear = new javax.swing.JLabel();
        lbl_warning = new javax.swing.JLabel();
        lbl_Preferences = new javax.swing.JLabel();
        cb_cconnection = new javax.swing.JCheckBox();
        cb_cuser = new javax.swing.JCheckBox();
        lbl_port = new javax.swing.JLabel();
        txt_port = new javax.swing.JTextField();
        btn_Save = new javax.swing.JButton();
        btn_cancel = new javax.swing.JButton();

        setOpaque(false);

        pn_Container.setOpaque(false);

        lbl_Password.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Password.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbl_Password.setText("KeyStore Password:");
        lbl_Password.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        lbl_titGlobal.setFont(new java.awt.Font("Dialog", 1, 14));
        lbl_titGlobal.setForeground(new java.awt.Color(204, 204, 204));
        lbl_titGlobal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/certificate.png"))); // NOI18N
        lbl_titGlobal.setText("Global KeyStore");

        pwd_password.setBackground(new Color(0,0,0,0));
        pwd_password.setForeground(new java.awt.Color(204, 204, 204));
        pwd_password.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pwd_password.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        pwd_password.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        pwd_password.setOpaque(false);
        pwd_password.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                pwd_passwordFocusLost(evt);
            }
        });

        lbl_login.setFont(new java.awt.Font("Dialog", 1, 14));
        lbl_login.setForeground(new java.awt.Color(204, 204, 204));
        lbl_login.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/userlogin.png"))); // NOI18N
        lbl_login.setText("User Login");

        lbl_username.setForeground(new java.awt.Color(204, 204, 204));
        lbl_username.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/users.png"))); // NOI18N
        lbl_username.setText("Username:");

        txt_user.setBackground(new Color(0,0,0,0));
        txt_user.setForeground(new java.awt.Color(204, 204, 204));
        txt_user.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txt_user.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        txt_user.setOpaque(false);

        cb_DNIe.setForeground(new java.awt.Color(204, 204, 204));
        cb_DNIe.setText("DNIe");
        cb_DNIe.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        cb_DNIe.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cb_DNIe.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/secure-card-bw.png"))); // NOI18N
        cb_DNIe.setOpaque(false);
        cb_DNIe.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cb_DNIeItemStateChanged(evt);
            }
        });

        lbl_Keystore.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Keystore.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbl_Keystore.setText("KeyStore:");
        lbl_Keystore.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        lbl_ksFile.setForeground(new java.awt.Color(204, 204, 204));
        lbl_ksFile.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_ksFile.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        lbl_ksFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbl_ksFileMouseClicked(evt);
            }
        });

        lbl_Clear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/clear.png"))); // NOI18N
        lbl_Clear.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_Clear.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbl_ClearMouseClicked(evt);
            }
        });

        lbl_warning.setForeground(new java.awt.Color(204, 204, 204));
        lbl_warning.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/warning.png"))); // NOI18N
        lbl_warning.setText("<html>Warning! Password will be saved in a plain text file. If password is not set, you will be asked for each session.</html>");
        lbl_warning.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        lbl_Preferences.setFont(new java.awt.Font("Dialog", 1, 14));
        lbl_Preferences.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Preferences.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/preferences.png"))); // NOI18N
        lbl_Preferences.setText("Preferences");

        cb_cconnection.setForeground(new java.awt.Color(204, 204, 204));
        cb_cconnection.setText("Check server");
        cb_cconnection.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cb_cconnection.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/connect_bw.png"))); // NOI18N
        cb_cconnection.setOpaque(false);
        cb_cconnection.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cb_cconnectionItemStateChanged(evt);
            }
        });

        cb_cuser.setForeground(new java.awt.Color(204, 204, 204));
        cb_cuser.setText("Check User");
        cb_cuser.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cb_cuser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/user_info_bw.png"))); // NOI18N
        cb_cuser.setOpaque(false);
        cb_cuser.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cb_cuserItemStateChanged(evt);
            }
        });

        lbl_port.setForeground(new java.awt.Color(204, 204, 204));
        lbl_port.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/net.png"))); // NOI18N
        lbl_port.setText("Port:");

        txt_port.setBackground(new Color(0,0,0,0));
        txt_port.setForeground(new java.awt.Color(204, 204, 204));
        txt_port.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txt_port.setText("46600");
        txt_port.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        txt_port.setOpaque(false);

        javax.swing.GroupLayout pn_ContainerLayout = new javax.swing.GroupLayout(pn_Container);
        pn_Container.setLayout(pn_ContainerLayout);
        pn_ContainerLayout.setHorizontalGroup(
            pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_ContainerLayout.createSequentialGroup()
                .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(pn_ContainerLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(lbl_warning, 0, 0, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pn_ContainerLayout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pn_ContainerLayout.createSequentialGroup()
                                    .addGap(12, 12, 12)
                                    .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(pn_ContainerLayout.createSequentialGroup()
                                            .addComponent(lbl_Keystore, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(lbl_ksFile, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(lbl_Clear))
                                        .addGroup(pn_ContainerLayout.createSequentialGroup()
                                            .addComponent(lbl_Password)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(pwd_password, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addComponent(lbl_titGlobal)
                                .addComponent(lbl_login)))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pn_ContainerLayout.createSequentialGroup()
                            .addGap(100, 100, 100)
                            .addComponent(lbl_username)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txt_user, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(cb_DNIe, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(36, 36, 36)))
                    .addGroup(pn_ContainerLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pn_ContainerLayout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(cb_cconnection)
                                .addGap(39, 39, 39)
                                .addComponent(cb_cuser)
                                .addGap(45, 45, 45)
                                .addComponent(lbl_port)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txt_port, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lbl_Preferences))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pn_ContainerLayout.setVerticalGroup(
            pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_ContainerLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_titGlobal)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl_Clear, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_ksFile, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_Keystore))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_Password)
                    .addComponent(pwd_password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbl_login)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_username)
                    .addComponent(cb_DNIe)
                    .addComponent(txt_user, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbl_Preferences)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pn_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cb_cconnection)
                    .addComponent(cb_cuser)
                    .addComponent(lbl_port)
                    .addComponent(txt_port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                .addComponent(lbl_warning, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        btn_Save.setBackground(new java.awt.Color(0, 0, 0));
        btn_Save.setForeground(new java.awt.Color(204, 204, 204));
        btn_Save.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/save.png"))); // NOI18N
        btn_Save.setText("Save");
        btn_Save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SaveActionPerformed(evt);
            }
        });

        btn_cancel.setBackground(new java.awt.Color(0, 0, 0));
        btn_cancel.setForeground(new java.awt.Color(204, 204, 204));
        btn_cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/dialog-cancel.png"))); // NOI18N
        btn_cancel.setText("Cancel");
        btn_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(362, Short.MAX_VALUE)
                .addComponent(btn_cancel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_Save)
                .addContainerGap())
            .addComponent(pn_Container, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(pn_Container, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_Save)
                    .addComponent(btn_cancel))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void lbl_ksFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_ksFileMouseClicked
        JFileChooser jfc = new JFileChooser();
        jfc.setDialogTitle("Select your KeyStore file:");
        jfc.setDialogType(JFileChooser.OPEN_DIALOG);
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int status = jfc.showOpenDialog(this);
        if(status == JFileChooser.CANCEL_OPTION) return;
        if(status == JFileChooser.ERROR_OPTION){
            pn_Info.Load((JPanel)this.getParent(), this, "Error opening file", "It was impossible to open the KeyStore file.<br> Check it and try again.", pn_Info.ICON_ERROR);
            return;
        }
        lbl_ksFile.setText(jfc.getSelectedFile().getAbsolutePath());
        lbl_Clear.setVisible(true);
    }//GEN-LAST:event_lbl_ksFileMouseClicked

    private void lbl_ClearMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_ClearMouseClicked
       lbl_ksFile.setText("");
       lbl_Clear.setVisible(false);
    }//GEN-LAST:event_lbl_ClearMouseClicked

    private void pwd_passwordFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_pwd_passwordFocusLost
       lbl_warning.setVisible(pwd_password.getPassword().length>0);
    }//GEN-LAST:event_pwd_passwordFocusLost

    private void btn_SaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SaveActionPerformed
       BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(new File((String) kuasar.plugin.Intercom.ODR.getValue("$PLUGINDIR") + File.separator + Config.path + File.separator + Config.filecfg)));
            bw.write("keystore="+lbl_ksFile.getText()+"\n");
            bw.write("kspwd="+String.valueOf(pwd_password.getPassword()) + "\n");
            if(cb_DNIe.isSelected())
                bw.write("dnie\n");
            else
                bw.write("user=" + txt_user.getText()+"\n");
            if(cb_cconnection.isSelected())
                bw.write("checkserver\n");
            if(cb_cuser.isSelected())
                bw.write("checkuser\n");
            int port = 0;
            try{
                port=Integer.parseInt(txt_port.getText().trim());
            }catch(NumberFormatException ex){
                port =46600;
            }
            bw.write("port="+port+"\n");
            bw.flush();
            close();
            GUI.launchInfo("Configuration saved successfully!");
        } catch (IOException ex) {
            pn_Info.Load((JPanel) this.getParent(), this, "Error saving file", "I couldn't save preferences. <br>" + ex.getMessage() , pn_Info.ICON_ERROR);
        } finally{
            try {
                bw.close();
            } catch (IOException ex) {
            }
        }
    }//GEN-LAST:event_btn_SaveActionPerformed

    private void cb_DNIeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cb_DNIeItemStateChanged
         cb_DNIe.setIcon(cb_DNIe.isSelected()?new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/secure-card.png")):new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/secure-card-bw.png")));
        txt_user.setEditable(!cb_DNIe.isSelected());
        if(cb_DNIe.isSelected()) txt_user.setText("");
    }//GEN-LAST:event_cb_DNIeItemStateChanged

    private void cb_cconnectionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cb_cconnectionItemStateChanged
        cb_cconnection.setIcon(cb_cconnection.isSelected()? new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/connect.png")):new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/connect_bw.png")));
        if(!cb_cconnection.isSelected()) cb_cuser.setSelected(false);
    }//GEN-LAST:event_cb_cconnectionItemStateChanged

    private void cb_cuserItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cb_cuserItemStateChanged
         cb_cuser.setIcon(cb_cuser.isSelected()? new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/user_info.png")):new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/servermanager/icons/user_info_bw.png")));
         if(cb_cuser.isSelected()) cb_cconnection.setSelected(true);
    }//GEN-LAST:event_cb_cuserItemStateChanged

    private void btn_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelActionPerformed
        close();
    }//GEN-LAST:event_btn_cancelActionPerformed

    private void loadConfig(){
       Config.loadConfig();
       if(Config.GlobalServerCFG.keyStore!=null){
            lbl_ksFile.setText(Config.GlobalServerCFG.keyStore);
            if(lbl_ksFile.getText().length()>0) lbl_Clear.setVisible(true);
       }
       if(Config.GlobalServerCFG.ksPasswd!=null)
           pwd_password.setText(String.valueOf(Config.GlobalServerCFG.ksPasswd));
       if(Config.GlobalServerCFG.user!=null)
           txt_user.setText(Config.GlobalServerCFG.user);
       cb_DNIe.setSelected(Config.GlobalServerCFG.dnie);
       cb_cconnection.setSelected(Config.GlobalServerCFG.checkServer);
       cb_cuser.setSelected(Config.GlobalServerCFG.checkClient);
       txt_port.setText(String.valueOf(Config.GlobalServerCFG.port));
    }
    private void close(){
        GUI.loadPlugin(main);
        GUI.updateUI();
        GUI.visibleToolBar();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Save;
    private javax.swing.JButton btn_cancel;
    private javax.swing.JCheckBox cb_DNIe;
    private javax.swing.JCheckBox cb_cconnection;
    private javax.swing.JCheckBox cb_cuser;
    private javax.swing.JLabel lbl_Clear;
    private javax.swing.JLabel lbl_Keystore;
    private javax.swing.JLabel lbl_Password;
    private javax.swing.JLabel lbl_Preferences;
    private javax.swing.JLabel lbl_ksFile;
    private javax.swing.JLabel lbl_login;
    private javax.swing.JLabel lbl_port;
    private javax.swing.JLabel lbl_titGlobal;
    private javax.swing.JLabel lbl_username;
    private javax.swing.JLabel lbl_warning;
    private javax.swing.JPanel pn_Container;
    private javax.swing.JPasswordField pwd_password;
    private javax.swing.JTextField txt_port;
    private javax.swing.JTextField txt_user;
    // End of variables declaration//GEN-END:variables
}
